package com.tencent.search.controller;

import com.tencent.search.pojo.CourseEntity;
import com.tencent.search.service.elasticService;
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("elastic")
public class ElasticController {

    @Resource
    private elasticService es;

    @RequestMapping("/searchFromEs")
    public List<CourseEntity> searchFromEs(@RequestBody Map<String, Object> params){
        List<CourseEntity> page = es.searchFromEs(params);
        return page;
    }

    @RequestMapping("/getById")
    public CourseEntity getById(@RequestParam("id") Long id){
        CourseEntity courseEntity = es.getById(id);
        return courseEntity;
    }

    @RequestMapping("/searchCourse")
    Map<String,Object> searchCourse(@RequestParam Map<String, Object> paramMap){
        Map<String, Object> resultMap = es.searchCourse(paramMap);
        return resultMap;
    }

    @RequestMapping("/save")
    public void save(@RequestBody CourseEntity course){
        es.save(course);
    }

    @RequestMapping("/updateById")
    public void updateById(@RequestBody CourseEntity courseEntity){
        es.updateById(courseEntity);
    }

    @RequestMapping("/delete")
    public void delete(@RequestBody Long[] ids){
        es.delete(ids);
    }

    @RequestMapping("saveAll")
    public void saveAll(@RequestBody List<CourseEntity> list){
        es.saveAll(list);
    }

}
